home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 April / macformat-023.iso / Shareware City / Developers / NeoPersist 3.0.8 folder / NeoBench / Source / CNeoBenchApp.cp < prev    next >
Encoding:
Text File  |  1994-10-13  |  4.6 KB  |  212 lines  |  [TEXT/MMCC]

  1. /*****
  2.  * CNeoBenchApp.cp
  3.  *
  4.  *    Application methods for a typical application.
  5.  *
  6.  *  Copyright © 1992-1993 NeoLogic Systems.  All rights reserved.
  7.  *
  8.  *****/
  9.  
  10. #include "NeoTypes.h"
  11. #include <stdlib.h>
  12. #include <Timer.h>
  13. #include "UDesktop.h"
  14. #include "UMemoryMgr.h"
  15. #include "UPowerTools.h"
  16. #include "LGrowZone.h"
  17. #include "LList.h"
  18. #include "CNeoWindow.h"
  19. #include CNeoMetaClassH
  20. #include "CNeoBenchApp.h"
  21. #include "CNeoBenchDoc.h"
  22. #include CNeoDatabaseNativeH
  23. #include "CFiller.h"
  24.  
  25. extern    OSType    gSignature;
  26.  
  27. int main(void)
  28. {
  29.     CNeoBenchApp *    app;
  30.  
  31.     InitializeHeap(4);
  32.     ::InitializeToolbox();
  33.     new LGrowZone(20000);
  34.  
  35.     app = new CNeoBenchApp();
  36.     app->Run();
  37.     delete app;
  38.  
  39.     return 0;
  40. }
  41.  
  42. /***
  43.  * CNeoBenchApp
  44.  *
  45.  *    Initialize the application. Your initialization method should
  46.  *    at least call the inherited method. If your application class
  47.  *    defines its own instance variables or global variables, this
  48.  *    is a good place to initialize them.
  49.  *
  50.  ***/
  51. CNeoBenchApp::CNeoBenchApp(void)
  52.     : CNeoAppRoot(kNeoBenchSig, kNeoBenchFileType)
  53. {
  54.     long        index;
  55.     long        delay    = 0;
  56.     TMTask        timer;
  57.  
  58.     FFileType = kNeoBenchFileType;
  59.  
  60.     // Add CFiller class to the metaclass table
  61.     new CNeoMetaClass(kFillerID, kNeoPersistID, kFillerName, CFiller::New);
  62.  
  63.     // Bound the default size of the NeoAccess object cache to be 3/4 of free memory
  64.     CNeoPersist::FCacheSize = ((FreeMem() / 4) * 3);
  65.  
  66.     // Just to make sure that we get more random results.
  67.     srand((unsigned int)clock());
  68.  
  69.     // measure Time Manager overhead
  70.     timer.tmAddr        = NULL;
  71.     timer.tmCount        = 0;
  72.     timer.tmWakeUp        = 0;
  73.     timer.tmReserved    = 0;
  74.     
  75.     for (index = 0; index < 100; index++) {
  76.         InsTime((QElemPtr)&timer);
  77.         PrimeTime((QElemPtr)&timer, k30MicroMinutes);
  78.         RmvTime((QElemPtr)&timer);
  79.         
  80.         if (timer.tmCount > 0)
  81.             // milliseconds
  82.             delay += -(k30MicroMinutes + timer.tmCount * 1000);
  83.         else
  84.             // negated microseconds
  85.             delay += -(k30MicroMinutes - timer.tmCount);
  86.     }
  87.     
  88.     // compute average overhead
  89.     gLoopOverhead = delay / 100;
  90. }
  91.  
  92. CNeoBenchApp::~CNeoBenchApp(void)
  93. {
  94. }
  95.  
  96. /***
  97.  * createDocument
  98.  *
  99.  *    The user chose New from the File menu.
  100.  *    In this method, you need to create a document and send it
  101.  *    a newFile message.
  102.  *
  103.  ***/
  104. CNeoDoc    *CNeoBenchApp::createDocument(void)
  105. {
  106.     CNeoBenchDoc *    document = nil;
  107.  
  108.     NEOTRY {
  109.         /**
  110.          **    Create your document.
  111.          **
  112.          **/
  113.         document = new CNeoBenchDoc(FALSE, TRUE, FALSE);
  114.         NeoFailNil(document);
  115.         document->SetSuperCommander(this);
  116.  
  117.         /**
  118.          **    Send the document a NewFile() message.
  119.          **    The document will open a window, and
  120.          **    set up the heart of the application.
  121.          **
  122.          **/
  123.         document->newDatabase();
  124.     }
  125.     NEOCATCH {
  126.         /*
  127.          * This exception handler gets executed if a failure occurred
  128.          * anywhere within the scope of the TRY block above. Since
  129.          * this indicates that a new doc could not be created, we
  130.          * check if an object had been allocated and if it has, send
  131.          * it a unrefer message. The exception will propagate up to
  132.          * CSwitchboard's exception handler, which handles displaying
  133.          * an error alert.
  134.          */
  135.  
  136.         if (document) {
  137.             delete document;
  138.             document = nil;
  139.         }
  140.     }
  141.     NEOENDTRY;
  142.  
  143.     return document;
  144. }
  145.  
  146. /***
  147.  * OpenDocument
  148.  *
  149.  *    The user chose Open… from the File menu.
  150.  *    In this method you need to create a document
  151.  *    and send it an OpenFile() message.
  152.  *
  153.  *    The macSFReply is a good SFReply record that contains
  154.  *    the name and vRefNum of the file the user chose to
  155.  *    open.
  156.  *
  157.  ***/
  158.  
  159. void CNeoBenchApp::OpenDocument(FSSpec *aSpec)
  160. {
  161.     Boolean            remote;
  162.     CNeoBenchDoc *    document    = nil;
  163.  
  164. #ifdef qNeoShare
  165.     remote = fOpeningRemote;
  166. #else
  167.     remote = FALSE;
  168. #endif
  169.  
  170.     VOLATILE(document);
  171.  
  172.     NEOTRY {
  173.         // Our parent will check to see if this is a document we have already opened.
  174.         // If we find the file already open by the app, then fDocument will refer to it.
  175.         // If the file is opened but not by this app, then the parent will signal a failure.
  176.         inherited::OpenDocument(aSpec);
  177.         if (fDocument)
  178.             return;
  179.  
  180.         /**
  181.          **    Create your document.
  182.          **
  183.          **/
  184.         document = new CNeoBenchDoc(TRUE, FALSE, remote);
  185.         NeoFailNil(document);
  186.         document->SetSuperCommander(this);
  187.  
  188.         /**
  189.          **    Send the document an OpenFile() message.
  190.          **    The document will open a window, open
  191.          **    the file specified in the macSFReply record,
  192.          **    and display it in its window.
  193.          **
  194.          **/
  195.         document->openFile(aSpec);
  196.     }
  197.     NEOCATCH {
  198.         /*
  199.          * This exception handler gets executed if a failure occurred
  200.          * anywhere within the scope of the TRY block above. Since
  201.          * this indicates that the document could not be opened, we
  202.          * send it a unrefer message. The exception will propagate up to
  203.          * CSwitchboard's exception handler, which handles displaying
  204.          * an error alert.
  205.          */
  206.         if (document)
  207.             delete document;
  208.     }
  209.     NEOENDTRY;
  210. }
  211.  
  212.